<template>
    <div class="particulars">
        <v-detail :detailData="inputData" :inputConfig="inputConfig" :rules="rules" ref="input"></v-detail>
    </div>
</template>

<script>
import detail from "commons/Detail";
import baseMixin from "@/mixins/BaseMixin";

export default {
    name: "particulars",
    mixins: [baseMixin],
    props: {
        inputData: {
            type: Object
        }
    },
    data() {
        return {
            inputConfig: [
                [
                    {
                        type: "input",
                        label: this.$t('outbound.receiptvalidationkey'),
                        props: "receiptvalidationkey",
                        disabled: !this.$store.state.newFlag
                    },
                    {
                        type: "select",
                        label: this.$t('outbound.receiptwithoutlpn'),
                        props: "receiptwithoutlpn",
                        options: this.getOptions('querycodeLkup/ALLOWERROR')
                    },
                ],
                [
                    {
                        type: "checkbox",
                        label: this.$t('outbound.defaultflag'),
                        props: "defaultflag",
                    },
                    {
                        type: "select",
                        label: this.$t('outbound.receiptwithoutasn'),
                        props: "receiptwithoutasn",
                        options: this.getOptions('querycodeLkup/ALLOWERROR')
                    },
                    {
                        type: "select",
                        label: this.$t('outbound.commoditynotonasn'),
                        props: "commoditynotonasn",
                        options: this.getOptions('querycodeLkup/ALLOWERROR')
                    },
                ],
                [
                    {
                        type: "select",
                        label: this.$t('outbound.performqtyvalidation'),
                        props: "performqtyvalidation",
                        options: this.getOptions('querycodeLkup/YESNO')
                    },
                    {
                        type: "select",
                        label: this.$t('outbound.overagemessage'),
                        props: "overagemessage",
                        options: this.getOptions('querycodeLkup/YESNO')
                    },
                    {
                        type: "checkbox",
                        label: this.$t('outbound.overageoverride'),
                        props: "overageoverride",
                    },
                    {
                        type: "input",
                        label: " ",
                        props: "overageoveridepercent",
                    },
                    {
                        type: "checkbox",
                        label: this.$t('outbound.overageharderror'),
                        props: "overageharderror",
                    },
                    {
                        type: "input",
                        label: " ",
                        props: "overageharderrorpercent",
                    },
                ]
            ],
            rules: {
                receiptvalidationkey: [
                    {required: true, trigger: 'blur'},
                ],
                overageoveridepercent: [
                    {validator: this.maxcount, trigger: 'blur'},
                ],
                overageharderrorpercent: [
                    {validator: this.maxcount, trigger: 'blur'},
                ],
            },
        }
    },
    computed: {},
    methods: {
        maxcount(rule, value, callback) {
            if (value === '') {
                this.inputData[rule.field] = 0
                callback();
            } else {
                var re = /^[0-9]*$/;
                let te = value;
                let flag = re.test(te)
                if (flag) {
                    if (value < 0) {
                        this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                        this.inputData[rule.field] = 0
                        callback(new Error());
                    } else {
                        callback();
                    }
                } else {
                    this.$message.error(this.$t('app.inputGreaterZeroNumberPlease'))
                    this.inputData[rule.field] = 0
                    callback(new Error());
                }
            }
        },
    },
    mounted() {
    },
    components: {
        "v-detail": detail,
    },

}
</script>

<style scoped>

</style>
